Subscribe Us

Responsive Advertisement

Advertisement

1516A Tit for Tat codeforces solution in cpp

 

1516A Tit for Tat codeforces solution in cpp

by ujjal roy



#include<bits/stdc++.h>

using namespace std;

main()

{

    int t,n,k,i,r;

    cin>>t;

    while(t--)

    {

        cin>>n>>k;

        int a[n];

        for(i=0;i<n;i++) cin>>a[i];

       for(i=0;i<n-1&&k;i++)

       {

           r=min(a[i],k);

           k-=r;

           a[i]-=r;

           a[n-1]+=r;

       }




       for(i=0;i<n;i++)

       {

           cout<<a[i]<<" ";

       }

       cout<<endl;


    }

    return 0;

}


Post a Comment

0 Comments